package br.trainee.web.componentes;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import br.trainee.web.util.ResponseWrapper;

public class ValidatorTag extends BodyTagSupport{
	
	private String form;
	private String debug;
	private String submitHandler;
	private String ignore;
	private String invalidHandler;
	private String groups;
	private String onsubmitValidator;
	private String onfocusout;
	private String onkeyupValidator;
	private String onclickValidator;
	private String focusCleanup;
	private String errorPlacement;
	private String highlight;
	private String unhighlight;
	private String ignoreTitle;
	private String customFunctionValidation;

	public int doEndTag() throws JspException {
		
		JspWriter saida = pageContext.getOut();
		
		String corpo = getBodyContent().getString();
		
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
		
		ResponseWrapper responseWrapper = new ResponseWrapper(response);
		
		RequestDispatcher req = request.getRequestDispatcher("/resources/componentes-jsp/validator.jsp");
		
		request.setAttribute("form", form);
		request.setAttribute("corpo", corpo);
		request.setAttribute("debug", debug);
		request.setAttribute("submitHandler", submitHandler);
		request.setAttribute("ignore", ignore);
		request.setAttribute("invalidHandler", invalidHandler);
		request.setAttribute("groups", groups);
		request.setAttribute("onsubmitValidator", onsubmitValidator);
		request.setAttribute("onfocusout", onfocusout);
		request.setAttribute("onclickValidator", onclickValidator);
		request.setAttribute("onkeyupValidator", onkeyupValidator);
		request.setAttribute("focusCleanup", focusCleanup);
		request.setAttribute("errorPlacement", errorPlacement);
		request.setAttribute("highlight", highlight);
		request.setAttribute("unhighlight", unhighlight);
		request.setAttribute("ignoreTitle", ignoreTitle);
		request.setAttribute("customFunctionValidation", customFunctionValidation);
		
		try {
			
			req.include(request, responseWrapper);
			
			String conteudoComponente = responseWrapper.getString();
			
			saida.println(conteudoComponente);
			
		} catch (ServletException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return super.doEndTag();
	}

	
	
	public String getForm() {
		return form;
	}



	public void setForm(String form) {
		this.form = form;
	}

	public String getOnsubmitValidator() {
		return onsubmitValidator;
	}

	public void setOnsubmitValidator(String onsubmitValidator) {
		this.onsubmitValidator = onsubmitValidator;
	}

	public String getHighlight() {
		return highlight;
	}

	public void setHighlight(String highlight) {
		this.highlight = highlight;
	}

	public String getUnhighlight() {
		return unhighlight;
	}

	public void setUnhighlight(String unhighlight) {
		this.unhighlight = unhighlight;
	}

	public String getInvalidHandler() {
		return invalidHandler;
	}

	public void setInvalidHandler(String invalidHandler) {
		this.invalidHandler = invalidHandler;
	}

	public String getGroups() {
		return groups;
	}

	public void setGroups(String groups) {
		this.groups = groups;
	}

	public String getOnfocusout() {
		return onfocusout;
	}

	public void setOnfocusout(String onfocusout) {
		this.onfocusout = onfocusout;
	}

	public String getOnkeyupValidator() {
		return onkeyupValidator;
	}

	public void setOnkeyupValidator(String onkeyupValidator) {
		this.onkeyupValidator = onkeyupValidator;
	}

	public String getErrorPlacement() {
		return errorPlacement;
	}

	public void setErrorPlacement(String errorPlacement) {
		this.errorPlacement = errorPlacement;
	}



	



	public String getDebug() {
		return debug;
	}



	public void setDebug(String debug) {
		this.debug = debug;
	}



	public String getFocusCleanup() {
		return focusCleanup;
	}



	public void setFocusCleanup(String focusCleanup) {
		this.focusCleanup = focusCleanup;
	}



	public String getIgnoreTitle() {
		return ignoreTitle;
	}



	public void setIgnoreTitle(String ignoreTitle) {
		this.ignoreTitle = ignoreTitle;
	}



	public String getCustomFunctionValidation() {
		return customFunctionValidation;
	}



	public void setCustomFunctionValidation(String customFunctionValidation) {
		this.customFunctionValidation = customFunctionValidation;
	}



	public String getSubmitHandler() {
		return submitHandler;
	}



	public void setSubmitHandler(String submitHandler) {
		this.submitHandler = submitHandler;
	}



	public String getIgnore() {
		return ignore;
	}



	public void setIgnore(String ignore) {
		this.ignore = ignore;
	}



	public String getOnclickValidator() {
		return onclickValidator;
	}



	public void setOnclickValidator(String onclickValidator) {
		this.onclickValidator = onclickValidator;
	}
	
	
	
	
}
